package com.tuozixuan;

import java.io.File;
import java.util.List;
import java.util.Objects;

import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name = "custom")
public class CustomMojo extends AbstractMojo {

	@Parameter(name = "name", defaultValue = "test")
	private String name;
	
    @Parameter( defaultValue = "${plugin}", readonly = true )
    private PluginDescriptor plugin;
    
	@Parameter( defaultValue = "${project.basedir}", readonly = true )
    private File basedir;
	
	@Parameter(defaultValue = "${project.groupId}", readonly = true)
	private String groupId;
	
	@Parameter(defaultValue = "${project.artifactId}")
	private String artifactId;
	
	@Parameter(defaultValue = "${project.version}")
	private String version;
	
	@Parameter( defaultValue = "${project.dependencies}", readonly = true )
    private List<Dependency> dependencies;
	
	@Parameter( defaultValue = "${project.build.directory}", readonly = true )
    private File target;
	
	
	public void execute() throws MojoExecutionException, MojoFailureException {
		getLog().info("This is custom goal.");
		getLog().info("basedir: " + basedir.getAbsolutePath());
		getLog().info("target: " + target.getAbsolutePath());
		getLog().info("groupId: " + groupId);
		getLog().info("artifactId: " + artifactId);
		getLog().info("version: " + version);
		if (Objects.nonNull(dependencies)) {
			getLog().info("-------------------------------- Dependencies --------------------------------");
			for (Dependency dependency: dependencies) {
				String dependencyInfo = String.format("%s:%s:%s", dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
				getLog().info(dependencyInfo);
			}
		}
	}

}
